package model

import (
	"encoding/json"
	"fmt"
	"testing"

	_ "github.com/influxdata/influxdb1-client"
	client "github.com/influxdata/influxdb1-client/v2"
)

func TestQuery(t *testing.T) {
	invokeList := make([]*Invoke, 0)
	c, err := client.NewHTTPClient(client.HTTPConfig{
		Addr: "http://10.110.64.31:30440",
	})
	if err != nil {
		fmt.Println("Error creating InfluxDB Client: ", err.Error())
	}
	defer func() {
		_ = c.Close()
	}()
	q := client.NewQuery("select count(id), sum(runtime_duration) from invoke group by creator", InfluxDBName, "")
	if response, err := c.Query(q); err == nil && response.Error() == nil {
		fmt.Println(response)
	}
	jsonStr, _ := json.Marshal(invokeList)
	fmt.Println(string(jsonStr))
}
